package com.gzdh.dishrecognition.ui.pre;

import android.content.Context;
import android.view.Display;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.gzdh.dishrecognition.R;
import com.gzdh.dishrecognition.config.ProductConst;
import com.gzdh.dishrecognition.config.SysConstConfig;
import com.gzdh.dishrecognition.entity.FkEntity;
import com.gzdh.dishrecognition.ui.base.BasePresentation;

public class SelectPayPre extends BasePresentation {

    TextView tv_amount;
    TextView tv_close_time;
    private TextView cardNoTv;
    private TextView nameTv;
    private TextView btyeTv;
    private TextView msgTv;
    private TextView kyeTv;
    private ImageView weixinIcon;
    private ImageView aliIcon;

    private LinearLayout leftCancel;

    private LinearLayout cardInfoLinear;
    private LinearLayout selectPayLinear;

    private int clickCount = 0;

    public SelectPayPre(Context outerContext, Display display) {
        super(outerContext, display);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.pre_select_pay;
    }

    @Override
    protected void initView() {
        tv_amount = findViewById(R.id.tv_amount);
        tv_close_time = findViewById(R.id.tv_close_time);
        cardNoTv = findViewById(R.id.cardNoTv);
        nameTv = findViewById(R.id.nameTv);
        nameTv.setVisibility(View.GONE);
        btyeTv = findViewById(R.id.btyeTv);
        kyeTv = findViewById(R.id.kyeTv);
        cardInfoLinear = findViewById(R.id.cardInfoLinear);
        selectPayLinear = findViewById(R.id.selectPayLinear);
        msgTv = findViewById(R.id.msgTv);
        weixinIcon = findViewById(R.id.weixinIcon);
        aliIcon = findViewById(R.id.aliIcon);
        leftCancel = findViewById(R.id.leftCancel);
        leftCancel.setOnClickListener(view -> {
            clickCount++;
            if(clickCount >= 5) {
                dismiss();
                clickCount = 0;
            }
        });
        if (SysConstConfig.getInstance().isAllowWeixin()) {
            weixinIcon.setVisibility(View.VISIBLE);
        } else {
            weixinIcon.setVisibility(View.INVISIBLE);
        }

        if (SysConstConfig.getInstance().isAllowAli()) {
            aliIcon.setVisibility(View.VISIBLE);
        } else {
            aliIcon.setVisibility(View.INVISIBLE);
        }
    }

    @Override
    protected void initData() {
        tv_amount.setText(ProductConst.getInstance().getProductCartPrice());
    }

    public void setAmount(String amount) {
        tv_amount.setText(amount);
    }

    public TextView getTv_close_time() {
        return tv_close_time;
    }

    public void showCardInfo(JSONObject fk) {
        msgTv.setText("支付成功");
        selectPayLinear.setVisibility(View.GONE);
        cardInfoLinear.setVisibility(View.VISIBLE);
        cardNoTv.setText("卡号：" + fk.getString("cardno"));
        nameTv.setText("姓名：" + fk.getString("name"));
        btyeTv.setText("补贴余额：" + fk.getString("btye"));
        kyeTv.setText("自购余额：" + fk.getString("kye"));
    }


    public void showCardInfo(FkEntity fk) {
        msgTv.setText("支付成功");
        selectPayLinear.setVisibility(View.GONE);
        cardInfoLinear.setVisibility(View.VISIBLE);
        cardNoTv.setText("卡号：" + fk.getCardno());
        nameTv.setText("姓名：" + fk.getName());
        btyeTv.setText("");
        kyeTv.setText("");
    }

    public void showError(String msg) {
        msgTv.setText(msg);
    }
}
